import { Define, EntityObjectFactory } from 'tiny-entity2';
const EntityObjectType = EntityObjectFactory.GetEntityObjectType(process.env.dataBaseType || 'mysql');
@Define.Table({ TableName: "componet" })
export class Componet extends EntityObjectType<Componet>{
    @Define.PrimaryKey()
    id: string;

    /**
     * 组件名称
     *
     * @type {string}
     * @memberof Componet
     */
    @Define.Column({
        DataType: Define.DataType.VARCHAR,
    })
    name: string;

    @Define.Column({
        DataType: Define.DataType.VARCHAR,
    })
    type: string;

    @Define.Column({
        DataType: Define.DataType.VARCHAR,
    })
    selector: string;

    @Define.Column({
        DataType: Define.DataType.VARCHAR,
    })
    bindField: string;

    @Define.Column({
        DataType: Define.DataType.VARCHAR,
    })
    defaultValue: string;

    @Define.Column({
        DataType: Define.DataType.VARCHAR,
    })
    valueFilter: string;

    @Define.Column({
        DataType: Define.DataType.JSON,
    })
    dataSource: { key: string, value: string }[];

    @Define.Column({
        DataType: Define.DataType.JSON,
    })
    labelText: string;

    @Define.Column({
        DataType: Define.DataType.JSON,
    })
    fieldStyles: ICommonStyle[];

    @Define.Column({
        DataType: Define.DataType.JSON,
    })
    labelStyles: ICommonStyle[];

    @Define.Column({
        DataType: Define.DataType.VARCHAR,
    })
    size: string;

    @Define.Column({
        DataType: Define.DataType.BOOL,
    })
    disable: boolean;

    @Define.Column({
        DataType: Define.DataType.JSON,
    })
    validationRules: IValidator[];

    @Define.Column({
        DataType: Define.DataType.JSON,
    })
    extend: any;

    @Define.Column({
        DataType: Define.DataType.VARCHAR,
    })
    permitId: string;

    @Define.Column({
        DataType: Define.DataType.VARCHAR,
    })
    permitName: string;

    @Define.Column({
        DataType: Define.DataType.VARCHAR,
    })
    permitGroupName: string;
}

export interface IValidator {
    method: 'max' | 'min' | 'required' | 'minLength' | 'maxLength' | 'pattern';
    maxLengthValue?: number;
    minLengthValue?: number;
    maxValue?: number;
    minValue?: number;
    patternValue?: string | RegExp;
}

export const ComponetType = {
    Base: 'base'
}

export const BaseComponetSelector = {
    Input: 'input',
    Select: 'Select',
    Button: 'button',
    Upload: 'upload',
    AreaText: 'areaText',
    Table: 'table',
}

export interface ICommonStyle {

}